// 如果登录成功显示的应该是用户名和注销按钮
$(function() {
    // <div class="public-head-right">
    //     <a href="login.html" target="_blank">登录</a>
    //     <a href="register.html" target="_blank">注册</a>
    // </div>
    // 发送异步请求获取登录用户信息
    $.getJSON("/api/user/getCurrentUser", ret => {
        console.log(ret);
        if (ret["code"] === 1010) {
            // 已经登录
            let loginStatusStr = `
                ${ret.data.name},
                <a href="javascript:logout();">注销</a>
            `;
            $("div.public-head-right").html(loginStatusStr);
        } else {
            // 没有登录
        }
    });

    // 发送请求获取产品信息并显示
    // 新用户专享
    $.getJSON("/api/loan/0", ret => {
        console.log(ret);
        if (ret["code"] === 1200) {
            // 新手宝信息查询成功
            let str_new_user_sm = `
                <span>${ret["data"][0]["bidMinLimit"]}元起投</span>
                <span>投资最高限额${ret["data"][0]["bidMaxLimit"]}元</span>
                <span>当日即系</span>
            `;
            $("div.new-user-sm").html(str_new_user_sm);
            let str_new_user_number = `
                 <ul>
                    <li>
                        <p><b>${ret["data"][0]["rate"]}</b>%</p>
                        <span>历史年化收益率</span>
                    </li>
                    <li>
                        <p><b>${ret["data"][0]["cycle"]}</b>个月</p>
                        <span>投资周期</span>
                    </li>
                    <li>
                        <p><b>${ret["data"][0]["leftProductMoney"]}</b>元</p>
                        <span>余利可投资金额</span>
                    </li>
                </ul>
                <a href="details.html" target="_blank" class="new-user-btn">立即投资</a>
            `;
            $("div.new-user-number").html(str_new_user_number);
        }
    });
});

// 注销函数
function logout(){
    if (confirm("您确认注销该账号吗")) {
        // 如果是true表示确认注销
        $.getJSON("/api/user/logout", ret => {
            console.log(ret);
            alert(ret["msg"]);
            if (ret["code"] === 1012) {
                // 注销成功
                window.location.href = "/api/login";
            }
        });
    }
}
var swiper1 = new Swiper('.swiper-container.banner-lb', {
    pagination: '.swiper-pagination',
    paginationClickable: true,
    centeredSlides: true,
    autoplay: 3000,
    autoplayDisableOnInteraction: false,
    slidesPerView: 1,
    loop: true
});

